package com.onlocation.gui;

import android.content.Intent;
import android.os.Bundle;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapView;
import com.onlocation.R;

/**
 * Author: Steve Carrell
 * Date: 5/14/12
 */
public class LocateMap extends MapActivity {
    public static final int LOCATE_MAP_REQUEST_CD = 2;
    public static final int LOCATE_MAP_RESULT_CD = 1;

    public static final int E6 = 1000000;
    private MapView mapView;
    private GeoPoint point = new GeoPoint(0, 0);

    @Override
    protected boolean isRouteDisplayed() {
        return false;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.locate_map);
        mapView = (MapView) findViewById(R.id.mapview);
        mapView.setBuiltInZoomControls(true);
        int longE6 = (int) (getIntent().getExtras().getDouble("longitude") * E6);
        int latE6 = (int) (getIntent().getExtras().getDouble("latitude") * E6);
        point = new GeoPoint(latE6, longE6);
    }
    
    @Override
    public void onBackPressed() {
        Double longitude = ((double) point.getLongitudeE6()) / ((double) E6);
        Double latitude = ((double) point.getLatitudeE6()) / ((double) E6);
        Intent intent = new Intent();
        Bundle send = new Bundle();
        send.putDouble("longitude", longitude);
        send.putDouble("latitude", latitude);
        intent.putExtras(send);
        setResult(LOCATE_MAP_RESULT_CD, intent);
        super.onBackPressed();
    }
}
